// 220104 2218

// 压缩、解压缩
// 通过命令函参数来执行

var fs = require('fs');
var zlib = require('zlib');

// 获取变量
console.log(process.argv);

var cmd = process.argv[2];
console.log('执行 cmd=' + cmd);
// 先要执行zip，然后才有 *.gz 文件，然后才可以解压
if (cmd == 'zip') {
	fs.createReadStream('22M01/file/input01042245.txt')
		.pipe(zlib.createGzip())
		.pipe(fs.createWriteStream('22M01/file/input01042245.txt.gz'));
	console.log('文件zip完成');
} else if (cmd == 'unzip') {
	fs.createReadStream('22M01/file/input01042245.txt.gz')
		.pipe(zlib.createGunzip())
		.pipe(fs.createWriteStream('22M01/file/unzip01042229.txt'));
	console.log('文件unzip完成');	
} else {
	console.log('WARNING：不支持的命令');
}
